package com.punch.system.controller;


import com.punch.common.dto.system.semester.SemesterDTO;
import com.punch.common.model.Result;
import com.punch.common.page.PageInfo;
import com.punch.common.query.syste.SemesterQueryInfo;
import com.punch.common.vo.system.SemesterVO;
import com.punch.system.service.SemesterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 学期表 前端控制器
 * </p>
 *
 * @author wjj
 * @since 2020-11-25
 */
@RestController
@Api(value = "SemesterController", tags = "学期管理Controller")
public class SemesterController {

    @Autowired
    private SemesterService semesterService;


    /**
     * 学期列表
     *
     * @param semesterQueryInfo 学期查询条件
     * @return PageInfo<SemesterVO>
     */
    @GetMapping(value = "/semesters", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "学期列表", notes = "学期列表", produces = "application/json")
    public Result<PageInfo<SemesterVO>> listSemester(@ModelAttribute SemesterQueryInfo semesterQueryInfo) {
        return Result.succeed(semesterService.listSemester(semesterQueryInfo));
    }


    /**
     * 新增学期
     *
     * @param semesterDTO 新增学期
     * @return semesterId
     * @author wujj
     * @since 2020/6/4 19:33
     */
    @PostMapping(value = "/semester", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "新增学期", notes = "新增学期", produces = "application/json; charset=utf-8")
    public Result<Long> saveSemester(@Valid @RequestBody SemesterDTO semesterDTO) {
        return Result.succeed(semesterService.saveSemester(semesterDTO));
    }

    /**
     * 修改学期
     *
     * @param semesterDTO 学期表单
     * @return semesterId
     * @author wujj
     * @since 2020/6/4 19:33
     */
    @PutMapping(value = "/semester", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "修改学期", notes = "修改学期", produces = "application/json; charset=utf-8")
    public Result<Long> updateSemester(@Valid @RequestBody SemesterDTO semesterDTO) {
        return Result.succeed(semesterService.updateSemester(semesterDTO));
    }

    /**
     * 删除学期
     *
     * @param semesterId 学期id
     * @return long
     */
    @DeleteMapping(value = "/semester/{semesterId}", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "删除学期", notes = "删除学期", produces = "application/json; charset=utf-8")
    public Result<Long> deleteSemester(@PathVariable Long semesterId) {
        return Result.succeed(semesterService.deleteSemester(semesterId));
    }


}
